package structtest

import "fmt"

func Test() {
	fmt.Println("结构体开始")
	var user User
	user.Name = "张三"
	user.Age = 18
	user.Sex = "男"
	fmt.Println(user)
	fmt.Println("------------")
	user2 := User{"李四", 19, "女"}
	fmt.Println(user2)
	fmt.Println("------------")
	user3 := new(User2)
	fmt.Printf("%T\n", user3)
	fmt.Printf("p2=%#v\n", user3)
	fmt.Println("------------")
	aaa()
}

type User struct {
	Name string
	Age  int
	Sex  string
}
type User2 struct {
	Name string
	Age  int
	Sex  string
}
type User3 struct {
	Name string
	Age  int
	Sex  string
}

func aaa() {
	m := make(map[string]*User3)
	stus := []User3{
		{Name: "pprof.cn", Age: 18},
		{Name: "测试", Age: 23},
		{Name: "博客", Age: 28},
	}
	for _, stu := range stus {
		println(stu.Name)
	}
	for _, stu := range stus {
		// 使用临时变量创建新的 student 对象
		//println(stu)
		tempStu := stu
		m[stu.Name] = &tempStu
	}
	for k, v := range m {
		fmt.Println(k, "=>", v.Name)
	}
	println(m)
}
